<!--
    -  Copyright (c) 2018-2025, haohanwork.com All rights reserved.
  -->
<template>
    <div class="execution">
        <basic-container>
            <h2 class="io-goods-detail">
                基础信息
            </h2>
            <template>
                <el-row class="io-goods-detail basic-information">
                    <el-col :span="6"><div class="grid-content bg-purple">出库单号:{{basicInformation.exitWarehouseSn}}</div></el-col>
                    <el-col :span="6"><div class="grid-content bg-purple-light">出库类型:{{basicInformation.exitType}}</div></el-col>
                    <el-col :span="6"><div class="grid-content bg-purple"></div>状态:{{basicInformation.exitStatus}}</el-col>
                </el-row>
                <el-row class="io-goods-detail basic-information">
                    <el-col :span="6"><div class="grid-content bg-purple-light"></div>创建日期:{{basicInformation.createDate}}</el-col>
                    <el-col :span="6"><div class="grid-content bg-purple">关联单号:{{basicInformation.deliveryTime}}</div></el-col>
                    <el-col :span="6"><div class="grid-content bg-purple-light">制单人:{{basicInformation.createBy}}</div></el-col>
                </el-row>
                <el-row class="io-goods-detail basic-information">
                    <el-col :span="6"><div class="grid-content bg-purple"></div>仓库:{{basicInformation.warehouseSn}}</el-col>
                    <el-col :span="6"><div class="grid-content bg-purple"></div>备注:{{basicInformation.remarks}}</el-col>
                </el-row>
            </template>
        </basic-container>
        <basic-container>
            <h2 class="io-goods-detail">
                单据详情
            </h2>
            <template>
                <el-table :data="tableData" border show-summary style="width: 100%">
                    <el-table-column prop="goodsId" label="序号" type="index" width="180px"></el-table-column>
                    <el-table-column prop="productName" label="商品"></el-table-column>
                    <el-table-column prop="unit" sortable label="单位"></el-table-column>
                    <el-table-column prop="productNumber" label="出库数量" ></el-table-column>
                    <el-table-column prop="purchasePrice" sortable label="单价"></el-table-column>
                    <el-table-column prop="money" sortable label="金额">
                      <template slot-scope="scope">
                        <div>{{(scope.row.productNumber*scope.row.purchasePrice).toFixed(2)}}</div>
                      </template>
                    </el-table-column>
                </el-table>
            </template>
        </basic-container>
        <basic-container>
            <h2 class="io-goods-detail">
                单据修改记录
            </h2>
            <template>
                <el-table
                        :data="operationalHistory"
                        style="width: 100%"
                        :header-cell-style="{background:'#eef1f6',color:'#606266'}">
                    <el-table-column label="序号" prop="id" align="center" type="index"></el-table-column>
                    <el-table-column label="修改日期" prop="operatingTime" align="center"></el-table-column>
                    <el-table-column label="修改人" prop="operator" align="center"></el-table-column>
                    <el-table-column label="修改参数" prop="type" align="center"></el-table-column>
                    <el-table-column label="变更前参数" prop="log" align="center"></el-table-column>
                    <el-table-column label="变更后参数" prop="log" align="center"></el-table-column>
                </el-table>
            </template>
            <template>
                <div class="return-btn">
                    <el-button type="primary" plain @click="backup">返回</el-button>
                </div>
            </template>
        </basic-container>
    </div>
</template>
<!-- 采购退货 -->
<script>
    import {
      queryList
    } from "@/api/scm/warehouse/exit_warehouse";
    import { tableOption } from "@/const/crud/scm/warehouse/exit_warehouse";
    import {
        mapGetters
    } from 'vuex'
    import Util from '@/util/pds/utils'
    let cookieUtil = new Util();
    export default {
        name: 'addpurchaseback',
        data() {
            return {
                tableData: [],
                otherMoney:100,
                calcMoney:1000,
                basicInformation:{
                    purchaseOrderId:'POI10000',
                    checkStatus:'待审核',
                    purchaseType:'平台直购',
                    supplierName:'浩瀚小店',
                    deliveryTime:'2019-03-09',
                    purchaseEmployee:'张**',
                    makeBill:'运营'
                },
                operationalHistory:[]
            }
        },
        computed: {
            ...mapGetters(['permissions'])
        },
        created(){
          this.init();
        },
        methods:{
            init() {
              let param = {};
              param.pmId=this.getStore({name: "pmId"});

              param.exitWarehouseSn = this.$route.query.exitWarehouseSn.exitWarehouseSn;
              this.basicInformation = this.$route.query.exitWarehouseSn;
              queryList(param).then(res =>{
                this.tableData = res.data.data;
              })
            },
            // 数据合计
            getSummaries(param){
              const { columns, data } = param;
              const sums = [];
              columns.forEach((column, index) => {
                if (index === 0) {
                  sums[index] = '合计';
                  return;
                }else if(index !== 3 && index !== 5 ){
                  sums[index] = '';
                  return;
                }
                const values = data.map(item => Number(item[column.property]));
                if (!values.every(value => isNaN(value))) {
                  sums[index] = values.reduce((prev, curr) => {
                    const value = Number(curr);
                    if (!isNaN(value)) {
                      return prev + curr;
                    } else {
                      return prev;
                    }
                  }, 0);
                  sums[index] = sums[index].toFixed(2);
                } else {
                  sums[index] = 'N/A';
                }
              });
              return sums;
            },
            backup:function () {
                this.$router.go(-1);
            }
        }
    }
</script>

<style lang="scss" scoped>
    .io-goods-detail{
        margin-left: 10px;
    }
    .settle-accounts{
        text-align: right;
    }
    .basic-information {
        margin-top: 20px;
        font-weight: inherit;
    }
    .return-btn{
        height: 100px;
        width: 100%;
        text-align: center;
        line-height: 100px;
    }
</style>
